package com.hwz.gulimaill.thridParty.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * @Author: hwz
 * @CreateTime: 2025-10-18
 */

@Configuration
@ConfigurationProperties(prefix = "spring.mail")
@Data
public class SmsConfig {

    private String host;
    private String username;
    private String password;
    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost(host);
        mailSender.setPort(465);
        mailSender.setUsername(username);
        mailSender.setPassword(password);
        mailSender.setDefaultEncoding("UTF-8");


        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.ssl.enable", "true");  // 关键！启用SSL
        props.put("mail.smtp.starttls.enable", "false");  // 465端口不需要STARTTLS
        mailSender.setJavaMailProperties(props);
        return mailSender;
    }
}
